﻿#pragma once

// Floppy disk class
class FloppyDisk
{
public:
    FloppyDisk(UINT nTracks, UINT nSectorPerTrack, UINT nSectorSize);
    ~FloppyDisk();

    UINT GetTrackCount() const;

    UINT GetSectorCount() const;

    UINT GetSectorPerTrack() const;

    UINT GetSectorSize() const;

    UINT GetCapacity() const;

    BOOL Seek(UINT nTrack, UINT nSector);

    BOOL WriteImage(
        const CString& pszDevicePath,
        const CString& pszFilePath,
        PUINT pNumberOfTracksAffected,
        PUINT pNumberOfSectorsAffected,
        PUINT pNumberOfBytesWritten,
        CString& pszError);

    BOOL WriteMBR(const CString& pszDevicePath,
        const CString& pszFilePath,
        PUINT pNumberOfBytesWritten,
        CString& pszError);

protected:
    UINT GetLogicalBlockAddress(UINT nTrackNumber, UINT nSectorNumber) const;

    BOOL WriteBlock(HANDLE hDevice, UINT nBlockNumber, UINT nBlockSize,
        LPVOID lpBuffer, PUINT pNumberOfBytesWritten);

private:
    UINT m_nTracks = 0;
    UINT m_nSectorPerTrack = 0;
    UINT m_nSectorSize = 0;
    UINT m_nSectorCount = 0;
    UINT m_nCapacity = 0;
    UINT m_nCurrentTrackNumber = 0;
    UINT m_nCurrentSectorNumber = 0;
};